const state = {
	count: 0,
};

const getters = {
	oddOrEven(state) {
		return (state.count & 1) === 1 ? "奇数" : "偶数";
	},
};

const actions = {
	incrementAsync({ commit }, val) {
		setTimeout(() => {
			commit("INCREMENT", val);
		}, 1000);
	},
};

const mutations = {
	INCREMENT(state, val) {
		// state就是vuex管理state数据
		state.count += val;
	},
	DECREMENT(state, val) {
		state.count -= val;
	},
};

export default {
	namespaced: true, // 开启命名空间，所有数据（state\getter\actions\mutations）都会在模块下才能使用
	state,
	getters,
	actions,
	mutations,
};
